package logic

import (
	"context"
	"develop/model/mysql"
	"develop/usersrpc/internal/svc"
	"develop/usersrpc/usersrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type TopicAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewTopicAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TopicAddLogic {
	return &TopicAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *TopicAddLogic) TopicAdd(in *usersrpc.TopicAddRequest) (*usersrpc.TopicAddResponse, error) {
	// todo: add your logic here and delete this line
	topicInof := &mysql.Topic_Inof{
		Topic_name:  in.TopicName,
		Topic_intro: in.TopicIntro,
	}
	err := topicInof.ToPicInofCreate(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &usersrpc.TopicAddResponse{
		TopicId: int64(topicInof.ID),
	}, nil
}
